<div style="margin:20px;">
	<h1>{ADD_TO_ALBUM_TITLE}</h1>
	{INPUT_A_NEW_ALBUM_NAME}:<br />
	<input type="text" id="new_album_name" class="inputtext" onchange="text_changed()" /><br />
	<!-- IF albums -->
	{OR_SELECT_A_ALBUM}:<br />
	<select id='old_album' onchange="select_changed()">
		<option value="">-</option>
	<!-- BEGIN albums -->
		<option value="{name}">{name}</option>
	<!-- END -->
	<!-- ENDIF -->
	</select>
	<br />
	<br />
	<input type="button" value="{ADD_ALBUM_SUBMIT}" id='add_to_album_button' onclick="go_add_album()" />&nbsp;&nbsp;<input type="button" onclick="close_popup()" value="{ADD_ALBUM_CLOSE}" /> <br />
	<a href="#" id="go_to_album" style="display:none">{GO_TO_ALBUM}</a>

	<script language="javascript">	
	function select_changed()
	{
		if ($('#old_album').val())
		{
			$('#new_album_name').val('');
		}
	}
	function text_changed()
	{
		if ($('#new_album_name').val())
		{
			$('#old_album').val('');
		}
	}
	
	function go_add_album()
	{
		var name = $('#new_album_name').val();
		if (!name)
			name = $('#old_album').val();
		if (name)
		{
			var ids = get_checked();
			if (ids)
			{
				$('#add_to_album_button').attr('disabled','disabled').attr('value','{SAVING}');
				$.post('admin.php?p=photo_album&m=add',{ ids:ids,name:name},function(s)
				{
					var id = parseInt(s);
					if (s.indexOf('success') != -1)
					{
						$('#add_to_album_button').attr('value','{SAVED}');
						$('#go_to_album').click(function()
						{
							window.location = 'admin.php?p=photo_album&action=sort&album_id='+id;
						}).fadeIn(200);
						setTimeout("close_popup()",30000);
					}
					else
					{
						alert(s);
						$('#add_to_album_button').removeAttr('disabled').attr('value','{ADD_ALBUM_SUBMIT}');
					}
				})
			}
		}
	}
	</script>
</div>


